Show the code
# Read in libraries
import pandas as pd
import numpy as np
from lets_plot import *
LetsPlot.setup_html(isolated_frame=True)Course DS 250
Taylor Everett
ages = pd.Series(["10-25", "10-25", "26-35", "56-85", "0-9", "46-55",
"56-85", "0-9", "26-35", "56-85", "0-9", "10-25"])
# Define age categories
def categorize_age(age_range):
if age_range in ["0-9", "10-25", "26-35"]:
return "young"
else:
return "old"
# Apply categorization
categories = ages.apply(categorize_age)
# Create a DataFrame with random values (to simulate associated data)
np.random.seed(42) # For reproducibility
data = pd.DataFrame({
"variable": categories,
"value": np.random.randint(10, 90, size=len(ages)) # Random values
})
# Create the box plot
lets_plot_plot = (ggplot(data) +
geom_boxplot(aes(x='variable', y='value'), fill='blue') +
ggsize(600, 600) +
ggtitle("Age Group Box Plot"))
# Show the plot
lets_plot_plotWhen done with a question, render it to a .html file and upload it for the question. Either re-downolad this template or file -> save as -> a new file name and then replace the text in the question with the new question text.